package controller;

import java.util.Collection;
import java.util.HashMap;

import model.Software;
import dao.SoftwareDAO;

public class SoftwareController {

	private SoftwareDAO softwareDAO;

	public boolean inserirSoftware(String descricao, String versao, boolean sistemaOperacional) throws Exception {
		Software software = new Software(0, descricao, versao, sistemaOperacional);
		return getSoftwareDAO().inserir(software);
	}
	
	public boolean alterarSoftware(int id, String descricao, String versao, boolean sistemaOperacional) throws Exception {
		Software software = buscarSoftwarePorId(id);
		software.setDescricao(descricao);
		software.setVersao(versao);
		software.setSistemaOperacional(sistemaOperacional);
		return getSoftwareDAO().alterar(software);
	}
	
	public boolean excluirSoftware(int id) throws Exception {
		Software software = buscarSoftwarePorId(id);
		return getSoftwareDAO().delete(software);
	}
	
	public Software buscarSoftwarePorId(int id) throws Exception {
		return getSoftwareDAO().buscarSoftwarePorId(id);
	}

	public Collection<HashMap<String, Object>> buscarDadosSoftwareBrowse() throws Exception {
		return getSoftwareDAO().buscarDadosSoftwareBrowse();
	}

	public Collection<Software> buscarTodos() throws Exception {
		return getSoftwareDAO().buscarTodos();
	}
	public SoftwareDAO getSoftwareDAO() {
		if (softwareDAO == null){
			softwareDAO = new SoftwareDAO();
		}
		return softwareDAO;
	}
}
